package com.ibeeking.found.open.api.feign.fallback;

import com.ibeeking.found.open.api.common.dto.ApiMemberInfoDTO;
import com.ibeeking.found.open.api.common.query.ApiMemberInfoQuery;
import com.ibeeking.found.open.api.common.query.MemberIdCodeQuery;
import com.ibeeking.found.open.api.common.query.QrCodeQuery;
import com.ibeeking.found.open.api.feign.MemberFeignClient;
import com.ibeeking.nematos.utils.result.ResponseCodeEnum;
import com.ibeeking.nematos.utils.result.ResponseResult;
import feign.Response;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;


/**
 * 降级工场
 *
 * @Author ibeeking
 * @date 2019/1/18
 */
@Component
public class MemberFeignFallbackFactory implements FallbackFactory<MemberFeignClient> {
    @Override
    public MemberFeignClient create(Throwable throwable) {
        return new MemberFeignClient() {

            @Override
            public ResponseResult<Long> queryAndCheckMemberIdByQrCode(MemberIdCodeQuery query) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，获取会员id失败。" + throwable.getMessage(), null);
            }

            @Override
            public ResponseResult<ApiMemberInfoDTO> apiQueryMemberInfo(ApiMemberInfoQuery query) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，查询会员信息失败。" + throwable.getMessage(), new ApiMemberInfoDTO());
            }

            @Override
            public Response memberQrCode(QrCodeQuery query) {
                return null;
            }
        };
    }
}
